package com.jhinwins.equipmenteb.equipmentebserver.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jhinwins.equipmenteb.equipmentebserver.entity.UserBean;
import com.jhinwins.equipmenteb.equipmentebserver.service.UserService;
import com.jhinwins.equipmenteb.equipmentebserver.utils.RespUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("user")
public class UserController {
    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 未登陆
     */
    @GetMapping("unlogin")
    public JSONObject unlogin() {
        return RespUtils.createResp(RespUtils.UN_LOGIN);
    }

    /**
     * 登陆
     */
    @PostMapping("login")
    public JSONObject login(@RequestParam String username, @RequestParam String password) {
        return RespUtils.createSucResp(userService.login(username, password));
    }

    /**
     * 注册
     */
    @PostMapping("regist")
    public JSONObject regist(@RequestBody String body) {
        UserBean userBean = JSON.parseObject(body, UserBean.class);
        return RespUtils.createSucResp(userService.regist(userBean));
    }
}
